package xyz.qduwo.servlet.manager;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import xyz.qduwo.dao.CategoryDao;
import xyz.qduwo.entity.CatgoryEntity;
import xyz.qduwo.util.RespUtils;

/**
 *
 * @author Administrator
 */
@WebServlet("/admin/manager/UpdateType")
public class UpdateType extends HttpServlet{
    CatgoryEntity category = null;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/x-json;charset=utf-8");
        int type_id = Integer.parseInt(req.getParameter("ID"));
        
        try{
            category = CategoryDao.getByTypeID(type_id);
            if(category.getIsShow() == 1)
                category.setIsShow(0);
            else
                category.setIsShow(1);
            
            CategoryDao.update(category);
            resp.getWriter().println(RespUtils.success());
        }catch(Exception ex){
            ex.printStackTrace();
            resp.getWriter().println(RespUtils.fail("更改失败"));
        }
    }
    
}
